<?php
namespace Admin\SystemBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Admin\SystemBundle\Entity\User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="Admin\SystemBundle\Repository\UserRepository")
 */
class User implements UserInterface, \Serializable {
	/**
	 * @ORM\Column(type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	private $id;

	/**
	 * @ORM\Column(type="string", length=25, unique=true)
	 */
	private $username;

	/**
	 * @ORM\Column(type="string", length=64)
	 */
	private $password;

	/**
	 * @var \Role
	 *
	 * @ORM\ManyToOne(targetEntity="Role", fetch="LAZY")
	 * @ORM\JoinColumns({
	 *   @ORM\JoinColumn(name="roles", referencedColumnName="id")
	 * })
	 */	
	private $profile;
	
	/**
	 * @ORM\Column(type="string", length=60, unique=true)
	 */
	private $email;

	/**
	 * @ORM\Column(name="is_active", type="boolean")
	 */
	protected $isActive;

	/**
	 * @ORM\Column(type="string", length=32)
	 */
	protected $salt;

	/**
	 * @ORM\Column(type="string", length=60)
	 */
	protected $nome;

	/** 
	 * 
	 */
	private $roles;
		
	/**
	 * @inheritDoc
	 */
	public function __construct() {
		$this->isActive = true;
		// may not be needed, see section on salt below
		// $this->salt = md5(uniqid(null, true));
	}

	/**
	 * @inheritDoc
	 */
	public function getUsername() {
		return $this->username;
	}

	/**
	 * @inheritDoc
	 */
	public function getSalt() {
		// you *may* need a real salt depending on your encoder
		// see section on salt below
		return null;
	}

	/**
	 * @inheritDoc
	 */
	public function getPassword() {
		return $this->password;
	}

	/**
	 * @inheritDoc
	 */
	public function eraseCredentials() {
	}

	/**
	 * @see \Serializable::serialize()
	 */
	public function serialize() {
		return serialize(
				array($this->id, $this->username, $this->password,
				// see section on salt below
				// $this->salt,
				));
	}

	/**
	 * @see \Serializable::unserialize()
	 */
	public function unserialize($serialized) {
		list($this->id, $this->username, $this->password, 
		// see section on salt below
		// $this->salt
		) = unserialize($serialized);
	}

	public function getId() {
		return $this->id;
	}

	public function setId($id) {
		$this->id = $id;
	}

	public function setUsername($username) {
		$this->username = $username;
	}

	public function setPassword($password) {
		$this->password = $password;
	}

	public function getEmail() {
		return $this->email;
	}

	public function setEmail($email) {
		$this->email = $email;
	}

	public function getIsActive() {
		return $this->isActive;
	}

	public function setIsActive($isActive) {
		$this->isActive = $isActive;
	}

	public function setSalt($salt) {
		$this->salt = $salt;
	}

	public function getNome() {
		return $this->nome;
	}

	public function setNome($nome) {
		$this->nome = $nome;
	}
	
	public function getProfile(){
		return $this->profile;
	}
	
	public function setProfile(Role $profile){
		$this->profile = $profile;
	}	

	public function getRoles() {		
		if ($this->profile) {
			$this->roles = array($this->profile->getRole());
		}
		return $this->roles;
	}
	
	public function setRoles($roles) {
		$this->roles = $roles;
	}	
}
?>